﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace homework3
{
    internal class Program
    {
        static void Main(string[] args)
        {
            List<int> li = new List<int>();
            Console.WriteLine("随机生成一个10个元素的数组：");
            for(int i=0;i<10;i++)
            {
                int randomNumber = GenerateRandomNumber(1, 100);
                li.Add(randomNumber);
                Console.Write(randomNumber);
                if(i<9)Console.Write(",");
            }
            //int Max =Program.getMax(li);
            Console.WriteLine();
            Console.Write("数组的最大值是：");
            Console.WriteLine(Program.getMax(li));
            Console.Write("数组的最小值是：");
            Console.WriteLine(Program.getMin(li));
            Console.Write("数组的和是：");
            Console.WriteLine(Program.getSum(li));
            Console.Write("数组的平均值是：");
            Console.WriteLine(Program.getAverage(li));
            Console.ReadKey();

        }
        //生成随机数
        static Random random = new Random();
        static int GenerateRandomNumber(int min,int max)
        {
            return random.Next(min, max);
        }
        //求最大值
        public static int getMax(List<int> li)
        {
            int length = li.Count;
            int maxNum = 0;
            for (int i = 0; i < length; i++)
            {
                if (li[i] > maxNum) maxNum = li[i];
            }
            return maxNum;
        }
        //求最小值
        public static int getMin(List<int> li)
        {
            int minNum = int.MaxValue;
            int length = li.Count;
            for (int i = 0; i < length; i++)
            {
                if (li[i] < minNum) minNum = li[i];
            }
            return minNum;
        }
        //求和
        public static int getSum(List<int> li)
        {
            int sum = 0;
            int length = li.Count;
            for (int i = 0; i < length; i++)
            {
                sum += li[i];
            }
            return sum;
        }
        //求平均值
        public static int getAverage(List<int> li)
        {
            int sum = getSum(li);
            int length = li.Count;
            int average = sum / length;
            return average;
        }
    }
}

